package com.hong.utils.phaser;

import java.util.concurrent.Phaser;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 * @Auther: Administrator
 * @Date: 2018/7/25 21:28
 * @Description:
 */
public class PhaserExample7 {

    public static void main(String[] args) throws InterruptedException {
       /* final Phaser phaser = new Phaser(3);
        Thread thread = new Thread(phaser::arriveAndAwaitAdvance);
        thread.start();
        System.out.println("====================");
        TimeUnit.SECONDS.sleep(10);

        thread.interrupt();
        System.out.println("=====thread.interrupt====");*/

       /*final Phaser phaser = new Phaser(3);
       Thread thread = new Thread(()->{
           try {
               phaser.awaitAdvanceInterruptibly(10);
               System.out.println("************************");
           } catch (InterruptedException e) {
               e.printStackTrace();
           }
       });
       thread.start();
        System.out.println("====================");
        TimeUnit.SECONDS.sleep(10);
        thread.interrupt();
        System.out.println("=====thread.interrupt====");*/
        /*可被中断的awaite方法*/
        final Phaser phaser = new Phaser(3);
        Thread thread = new Thread(()->{
            try {
                try {
                    phaser.awaitAdvanceInterruptibly(0,10,TimeUnit.SECONDS);
                } catch (TimeoutException e) {
                    e.printStackTrace();
                }
                System.out.println("************************");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        thread.start();

    }
}
